package com.oa.controller;

import com.oa.api.CardReplacementSreviceApi;
import com.oa.dto.Msg;
import com.oa.po.Tbl_card_replacement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

@RestController
public class CardReplacementController {
    @Autowired(required = false)

    CardReplacementSreviceApi cardReplacementSreviceApi;
    Msg msg = new Msg();
    //对外添加补卡申请的接口
    @CrossOrigin
    @PostMapping("/bb")
    public Msg addCard(@RequestBody Tbl_card_replacement tbl_card_replacement) {

        int i = cardReplacementSreviceApi.addCard(tbl_card_replacement);
        if (i == 1) {
            msg.setMsg("提交成功");
            msg.setCode(20000);
        } else {
            msg.setMsg("提交失败");
            msg.setCode(-20000);
        }
        return msg;
    }
    //对外查询补卡申请的接口
    @CrossOrigin
    @PostMapping("/cc")
    public Msg find(@RequestBody Map map){

        List<Tbl_card_replacement> tbl_card_replacements = cardReplacementSreviceApi.list_card(map);
        if (tbl_card_replacements!= null) {
            msg.setCode(200);
            msg.setMsg("查询成功");
            msg.setData(tbl_card_replacements);
        } else {
            msg.setCode(-100);
            msg.setMsg("查询失败");
        }
        return msg;
    }
}
